﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Xml;

namespace ValuationLogic
{
    public class Contract
    {
        //private const int MONTH_NUMBER = 12;
        public static Hashtable monthNum = new Hashtable();
        internal static Hashtable priceTable = new Hashtable();


        public static void init()
        {
            //refreshData();
            /*List<double> priceList = new List<double>();
            for (int i = 0; i <= 12; i++)
                //priceList.Add(i*10);
                priceList.Add(240.75);
            if (priceTable[2013] == null)
                priceTable.Add(2013, priceList);*/
        }
        internal static double getContractPrice(DateTime calDate, int year, int month)
        {
            //refreshData();
            // If we calculate on 7.2, our result is based on the data on 7.1
            // Because in my system the contract price on 7.2 won't know until 7.3
            DateTime myDate = calDate.AddDays(-1);
            while (myDate.DayOfWeek.ToString()[0] == 'S')
                myDate = myDate.AddDays(-1);
            
            int int_date = myDate.Month * 100000000 + myDate.Day * 1000000 + (myDate.Year - 2000) * 10000 + (year - 2000) * 100 + month;
            if (priceTable[int_date] != null)
                return (double)priceTable[int_date];
            else
                throw new Exception("Don't have enough data to calculate!");
        }

        internal static void MonthNameToNum()
        {
            if (monthNum.Count > 0) return;
            monthNum["JAN"] = 1;
            monthNum["FEB"] = 2;
            monthNum["MAR"] = 3;
            monthNum["APR"] = 4;
            monthNum["MAY"] = 5;
            monthNum["JUN"] = 6;
            monthNum["JLY"] = 7;
            monthNum["AUG"] = 8;
            monthNum["SEP"] = 9;
            monthNum["OCT"] = 10;
            monthNum["NOV"] = 11;
            monthNum["DEC"] = 12;
        }
    }
}

